package cc.orange.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * Created by CM on 2021/2/28.
 */

public class PopupSoftinputUtils {
    /*隐藏软键盘*/
    public static  void softinputDismiss(Activity context, View v){
        ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(v.getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
    }

    /*显示软键盘*/
    public static  void softinputShows(Activity context, View v){
        Handler handle=new Handler();
        handle.postDelayed(new Runnable() {
            @Override
            public void run() {
                v.requestFocus();
                v.setFocusable(true);
                InputMethodManager inputManager =
                        (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(v, 0);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    context.getWindow().setNavigationBarColor(Color.parseColor("#111111"));
                }
            }
        }, 200);
    }
}
